Skip to content

fix(migration): remaped snapshot tab paths and preserve uids on bru-t… - #8450

Merged
utkarsh-bruno merged 5 commits into
usebruno:mainfrom
ravindra-bruno:fix/bru-3683
Jul 6, 2026
Merged

utkarsh-bruno merged 5 commits into
usebruno:mainfrom
ravindra-bruno:fix/bru-3683

Conversation

@ravindra-bruno

@ravindra-bruno ravindra-bruno commented Jul 1, 2026 •

Copy link
Copy Markdown
Collaborator

BRU-3683

Description

Issue: When migrating a Bruno collection from the Bru format to YAML, any requests that are currently kept open during the conversion process break, displaying a "Request No Longer Exists" error. This affects both transient and normal requests.

Cause & Resolution: The issue occurs because the open tab/snapshot paths are broken and unique identifiers (UIDs) are lost during the migration. Added fix which remaps the snapshot tab paths and preserves the UIDs during the bru-to-yaml conversion.

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Summary by CodeRabbit

  • Bug Fixes
    • Improved the “.bru to .yml” collection migration so open request tabs stay correctly linked after conversion.
    • Updated persisted UI tab state during migration, including correct active-tab selection and response-example tab pathname handling.
    • Added resilient, best-effort tab path remapping so migration completion isn’t blocked by remapping issues.
  • Tests
    • Added unit coverage for snapshot tab-path remapping.
    • Added an end-to-end test to ensure pinned requests remain usable and no stale “missing request” messaging appears after migration.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR records migrated request paths during .bru to .yml conversion, remaps stored collection tab pathnames and active tab values, and adds unit and end-to-end tests covering the migration.

Changes

Snapshot tab remapping during YML migration

Layer / File(s) Summary
Track tabPathMap during migration
packages/bruno-electron/src/ipc/collection.js
Builds a tabPathMap while converting request and environment files, then calls snapshotManager.remapCollectionTabPaths after deleting the old artifacts.
SnapshotManager.remapCollectionTabPaths implementation
packages/bruno-electron/src/services/snapshot/index.js
Adds remapCollectionTabPaths(collectionPathname, pathMap), which normalizes input, remaps tab pathname and activeTab values, persists updates, and clears the lookup cache.
Remap coverage tests
packages/bruno-electron/tests/services/snapshot-remap.spec.js, tests/collection/migrate-to-yml/migrate-to-yml.spec.ts
Adds Jest coverage for pathname and active-tab remapping plus a Playwright migration test that verifies an open request tab still works after conversion.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant collection.js
  participant FileSystem
  participant SnapshotManager
  participant electron-store

  collection.js->>FileSystem: Convert .bru files to .yml
  collection.js->>collection.js: Record old path -> new path in tabPathMap
  collection.js->>FileSystem: Delete old .bru files and bruno.json
  collection.js->>SnapshotManager: remapCollectionTabPaths(collectionPathname, tabPathMap)
  SnapshotManager->>SnapshotManager: Normalize and apply pathname remaps
  SnapshotManager->>electron-store: Persist updated snapshot
Loading

Possibly related PRs

  • usebruno/bruno#7669: Extends the same YML migration flow and IPC handler that this PR updates with tab-path remapping.

Suggested reviewers: sid-bruno, vijayh-bruno, utkarsh-bruno, bijin-bruno, lohit-bruno

Poem

Old paths turned bright with YML light,
Tabs kept pace through migration night.
A snapshot hummed, paths in tune,
No request was lost too soon,
✨ Open tabs lived on just right.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the migration fix: remapping snapshot tab paths and preserving UIDs during bru-to-yml conversion.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
tests/collection/migrate-to-yml/migrate-to-yml.spec.ts (2)

154-154: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Extract the repeated ping item locator into a variable.

The .item-name locator filtered on "ping" is duplicated at Line 154 and Line 195.

🩹 Proposed fix
+    const pingItem = page.locator('.item-name').filter({ hasText: 'ping' });
+
     await test.step('Open the ping request as a permanent tab', async () => {
       await openCollection(page, 'migration-test');
-      await page.locator('.item-name').filter({ hasText: 'ping' }).dblclick();
+      await pingItem.dblclick();
     await test.step('The migrated request opens against the yml file and is runnable', async () => {
-      await page.locator('.item-name').filter({ hasText: 'ping' }).click();
+      await pingItem.click();

As per path instructions, "Use locator variables for locators."

Also applies to: 195-195

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/collection/migrate-to-yml/migrate-to-yml.spec.ts` at line 154, The
repeated ping item locator should be extracted into a shared variable in the
migration spec so the same .item-name filter is not duplicated. Update the
relevant test flow in migrate-to-yml.spec.ts by creating a locator variable for
the ping item and reuse it in both places where the current
page.locator('.item-name').filter({ hasText: 'ping' }) is used, keeping the test
readable and consistent with the locator-variable pattern.

Source: Path instructions


207-207: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Wrap the final page-error assertion in a test.step.

Every other assertion group in this test is wrapped in test.step for readable reports; this trailing check isn't.

🩹 Proposed fix
-    expect(pageErrors).toHaveLength(0);
+    await test.step('No uncaught page errors occurred during migration', async () => {
+      expect(pageErrors).toHaveLength(0);
+    });

As per path instructions, "Promote the use of test.step as much as possible so the generated reports are easier to read."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/collection/migrate-to-yml/migrate-to-yml.spec.ts` at line 207, The
trailing page-error check in migrate-to-yml.spec.ts is not wrapped in a
test.step like the other assertion groups. Update the final
expect(pageErrors).toHaveLength(0) assertion to run inside a test.step in the
same style used elsewhere in this test so the report remains consistent and
readable.

Source: Path instructions

packages/bruno-electron/src/services/snapshot/index.js (1)

207-283: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Implementation looks correct.

Normalization, validation, and remap logic (pathname + pathname::exampleName/pathname::exampleIndex suffix preservation) match the unit test expectations in snapshot-remap.spec.js.

Given this is a new cross-file public API consumed by collection.js, a short JSDoc on remapCollectionTabPaths documenting the pathMap contract (old→new absolute paths) and which activeTab accessors are handled would help future maintainers.

As per coding guidelines, "Add JSDoc comments to add more details to abstractions if needed."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-electron/src/services/snapshot/index.js` around lines 207 -
283, Add a short JSDoc for remapCollectionTabPaths in the snapshot service to
document the pathMap contract (old absolute path to new absolute path) and
clarify which activeTab accessors are remapped. Place it near the
remapCollectionTabPaths method in the Snapshot service so consumers like
collection.js can understand the API without inspecting the implementation. Keep
the description concise and focused on the supported pathname,
pathname::exampleName, and pathname::exampleIndex behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/bruno-electron/src/ipc/collection.js`:
- Around line 2738-2742: The try/catch around
snapshotManager.remapCollectionTabPaths in the collection IPC migration handler
is swallowing errors completely. Keep the best-effort behavior, but in the catch
block log the caught error with console.error so failures are observable,
matching the other error handling in this handler while still allowing migration
to continue.

---

Nitpick comments:
In `@packages/bruno-electron/src/services/snapshot/index.js`:
- Around line 207-283: Add a short JSDoc for remapCollectionTabPaths in the
snapshot service to document the pathMap contract (old absolute path to new
absolute path) and clarify which activeTab accessors are remapped. Place it near
the remapCollectionTabPaths method in the Snapshot service so consumers like
collection.js can understand the API without inspecting the implementation. Keep
the description concise and focused on the supported pathname,
pathname::exampleName, and pathname::exampleIndex behavior.

In `@tests/collection/migrate-to-yml/migrate-to-yml.spec.ts`:
- Line 154: The repeated ping item locator should be extracted into a shared
variable in the migration spec so the same .item-name filter is not duplicated.
Update the relevant test flow in migrate-to-yml.spec.ts by creating a locator
variable for the ping item and reuse it in both places where the current
page.locator('.item-name').filter({ hasText: 'ping' }) is used, keeping the test
readable and consistent with the locator-variable pattern.
- Line 207: The trailing page-error check in migrate-to-yml.spec.ts is not
wrapped in a test.step like the other assertion groups. Update the final
expect(pageErrors).toHaveLength(0) assertion to run inside a test.step in the
same style used elsewhere in this test so the report remains consistent and
readable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5bd59d33-ea7c-44b5-88fa-3ecc27940551

📥 Commits

Reviewing files that changed from the base of the PR and between 4f31e9b and b01b5b4.

📒 Files selected for processing (4)
  • packages/bruno-electron/src/ipc/collection.js
  • packages/bruno-electron/src/services/snapshot/index.js
  • packages/bruno-electron/tests/services/snapshot-remap.spec.js
  • tests/collection/migrate-to-yml/migrate-to-yml.spec.ts

@utkarsh-bruno utkarsh-bruno left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants